<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>
  
  <div class="container main-content">
  
    <div class="panel panel-default x-panel x-panel-layout">
    
       <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/user">用户管理</a></li>
          <li class="active">学员管理</li>
        </ol>
      </div>
    
      <div class="panel-body">
      
        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>
      
        <div class="col-xs-10 x-panel-layout-right">
          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>学员管理&nbsp;-&nbsp;学员列表</span></h2>
              <c:if test="${type eq 'offline'}">
                <div class="pull-right">
                  <c:choose>
                    <c:when test="${not empty currentPrincipal.site}">
                      <span class="current-branchCode">${currentPrincipal.site.name}</span>
                    </c:when>
                    <c:otherwise>
                      <select name="site">
                        <option value="">所有门店</option>
                        <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                          <option value="${site.id}" ${site.id == param.site ? 'selected' : ''}>${site.name}</option>
                        </c:forEach>
                      </select>
                    </c:otherwise>
                  </c:choose>
                </div>
              </c:if>
            </div>
          </div>
          
          <div class="x-toolbar-wrapper top-margin-20 clearfix">
            <div class="btn-group pull-right">
              <a href="${ctx.host}/${type}-students/export-view?siteId=${siteId}" data-target="#student-export" data-toggle="modal" title="导出数据" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;导出数据
              </a>
              <a href="${ctx.host}/${type}-students/exist" data-target="#student-mobile" data-toggle="modal" title="录入档案" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;录入档案
              </a>
              <a href="${ctx.host}/${type}-students/search${not empty queryString ? '?'.concat(queryString) : ''}" data-target="#" data-toggle="modal" title="过滤查询" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
              </a>
            </div>
          </div>
          
          <table class="table table-striped table-hover x-table bottom-margin-20">
            <thead>
              <tr>
                <th>姓名</th>
                <th>手机</th>
                <c:if test="${type eq 'offline'}"><th>课程</th></c:if>
                <th>首次购买时间</th>
                <th>总购买数</th>
                <th>是否录入档案</th>
                <th class="text-center">操作</th>
              </tr>
            </thead>
            <tbody>
              <c:forEach var="student" items="${students}">
                <tr>
                  <td>${student.name}</td>
                  <td>${student.mobile}</td>
                  <c:if test="${type eq 'offline'}">
                    <c:set var="currentSite" value="${empty currentPrincipal.site ? null : currentPrincipal.site.id}"/>
                    <td>
                      <c:forEach var="courseType" items="${persist.studentCourse(student.id, currentSite)}" varStatus="status">
                        ${status.index == 0 ? '' : '、'}${courseType.description}
                      </c:forEach>
                    </td>
                  </c:if>
                  <td><fmt:formatDate value="${student.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                  <td>${type eq 'online' ? student.stat.onlineCount : student.stat.individualCount+student.stat.groupCount+student.stat.yearCount}</td>
                  <td>${empty student.user.inputTime ? '否' : '是'}</td>
                  <td class="text-center">
                   <a href="${ctx.host}/${type}-students/${student.id}" title="详情">详情</a>
                 </td>
                </tr>
              </c:forEach>
            </tbody>
          </table>
          
          <div class="form-horizontal clearfix">
            
          <jsp:include page="/WEB-INF/include/page.jsp">
            <jsp:param name="url" value="${type}-students" />
            <jsp:param name="queryString" value="${queryString}" />
          </jsp:include>
          
          </div>
          
        </div>
      </div>
    </div>
  </div>
  
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/user/student-list.js">
    <script type="text/javascript">
      require(['page/user/student-list'], function(page) {
        page.init({
        	"filter": "${param.filter}",
        	"name": "${param.name}",
        	"mobile": "${param.mobile}"
        })
      })
    </script>
  </d:resource>
</body>
</html>